# -*- coding: utf-8 -*-
# @Time:2021/05/20 23:13
# @Author:Cindy
import json


def recursion(data, times=2):
    """
    递归函数
    :param data:原始数据
    :param times:倍数
    :return:如果原始数据为float类型，则数据翻倍
    """
    # 如果是dict和list，则循环递归，直到最后的数据为float或其他类型
    if isinstance(data, dict):
        for k, v in data.items():
            data[k] = recursion(v, times)

    elif isinstance(data, list):
        data = [recursion(i, times) for i in data]
        # for i in data:
        #     data = self.recursion(i, times)

    # 如果是float类型，则数据翻倍
    elif isinstance(data, float):
        data = data * times
    # 如果是其他数据类型，则直接返回
    else:
        data = data
    return data

if __name__ == '__main__':

    # org_data = {
    #         'cc': {'a': 12.3},
    #         'dd': {'b': 45.6}
    #     }
    # org_data = [
    #     {'a': 12.3},
    #     {'b': 45.6}
    # ]
    # recursion(org_data)
    org_data = json.load(open('quote.json', encoding='utf-8'))
    print(json.dumps(recursion(org_data, 3), indent=2))
